# -*- python -*-
# ex: set syntax=python:

# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from buildbot.scheduler import Nightly
from buildbot.scheduler import Scheduler
from twisted.internet import defer
from twisted.python import log
from twisted.python.failure import Failure

from master import gitiles_poller
from master import master_config
from master import master_utils
from master import slaves_list
from master.factory import annotator_factory

import config
import master_site_config

import os


ActiveMaster = master_site_config.V8
MAIL_NOTIFIER = ActiveMaster.is_production_host

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}
c['status'] = []


####### DATABASE

config.DatabaseSetup(c, require_dbconfig=ActiveMaster.is_production_host)

####### CHANGESOURCES

comparator = gitiles_poller.GitilesRevisionComparator()
c['change_source'] = [
  gitiles_poller.GitilesPoller(
    'https://chromium.googlesource.com/v8/v8',
    branches=['master'],
    pollInterval=10,
    comparator=comparator,
  ),
]

####### SCHEDULERS

## configure the Schedulers
# v8 Scheduler
s_v8 = Scheduler(name='v8_src',
                 branch='master',
                 treeStableTimer=0,
                 builderNames=['V8 Linux - debug builder',
                               'V8 Linux - nosnap builder',
                               'V8 Linux - nosnap debug builder',
                               'V8 Linux - shared',
                               'V8 Linux - vtunejit',
                               'V8 Linux - x87 - nosnap - debug builder',
                               'V8 Linux - predictable',
                               'V8 Linux64 - custom snapshot - debug builder',
                               'V8 Linux64 - debug builder',
                               'V8 Linux gcc 4.8',
                               'V8 Linux64 ASAN',
                               'V8 Linux64 TSAN',
                               'V8 Linux - arm64 - sim - MSAN',
                               'V8 Linux - noi18n - debug',
                               'V8 Win32 - builder',
                               'V8 Win32 - debug builder',
                               'V8 Win32 - nosnap - shared',
                               'V8 Win64',
                               'V8 Win64 - debug',
                               'V8 Mac',
                               'V8 Mac - debug',
                               'V8 Mac64',
                               'V8 Mac64 - debug',
                               'V8 Mac64 - xcode',
                               'V8 Mac GC Stress',
                               'V8 Mac64 ASAN',
                               'V8 Arm - builder',
                               'V8 Arm - debug builder',
                               'V8 Mips - builder',
                               'V8 Linux - arm - sim',
                               'V8 Linux - arm - sim - debug',
                               'V8 Linux - arm - sim - novfp3',
                               'V8 Linux - arm - sim - debug - novfp3',
                               'V8 Linux - arm64 - sim',
                               'V8 Linux - arm64 - sim - debug',
                               'V8 Linux - arm64 - sim - nosnap - debug - 1',
                               'V8 Linux - arm64 - sim - nosnap - debug - 2',
                               'V8 Linux - arm64 - sim - gc stress',
                               'V8 Linux - mipsel - sim - builder',
                               'V8 Linux - mips64el - sim - builder',
                               'V8 Linux - ppc - sim',
                               'V8 Linux - ppc64 - sim'])

# Scheduler for all revisions.
s_v8_all = Scheduler(name='v8_src_all',
                     branch='master',
                     treeStableTimer=0,
                     builderNames=['V8 Linux - builder',
                                   'V8 Linux64 - builder',
                                   'V8 Android Arm - builder',
                                   'V8 Android Arm64 - builder'])

# These builders run nightly.
s_v8_nightly = Nightly(name='v8_thrice_nightly',
                       branch=None,
                       builderNames=['V8 Linux - full debug',
                                     'V8 Linux - interpreted regexp',
                                     'V8 Random Deopt Fuzzer - debug'],
                       hour=[12],
                       minute=30)

c['schedulers'] = [
  s_v8,
  s_v8_all,
  s_v8_nightly,
]

builders = []

builder_priorities = {}

@defer.deferredGenerator
def prioritizeBuilders(buildmaster, builders):
  try:
    # Presort with default sorting function of builbot. The default sorting
    # takes the age of the latest build requests into account.
    sorter = (lambda:
        buildmaster.botmaster.brd._defaultSorter(buildmaster, builders))
    wfd = defer.waitForDeferred(defer.maybeDeferred(sorter))
    yield wfd
    builders = wfd.getResult()
  except:
    log.msg("Exception prioritizing builders; presorting failed")
    log.err(Failure())
  yield sorted(builders, key=lambda b: builder_priorities.get(b.name, 0))

c['prioritizeBuilders'] = prioritizeBuilders

# ----------------------------------------------------------------------------
# FACTORIES

m_annotator = annotator_factory.AnnotatorFactory()

# ----------------------------------------------------------------------------
# BUILDER DEFINITIONS

# The 'builders' list defines the Builders. Each one is configured with a
# dictionary, using the following keys:
#  name (required): the name used to describe this bilder
#  slavename (required): which slave to use, must appear in c['slaves']
#  builddir (required): which subdirectory to run the builder in
#  factory (required): a BuildFactory to define how the build is run
#  periodicBuildTime (optional): if set, force a build every N seconds
#  category (optional): it is not used in the normal 'buildbot' meaning. It is
#                       used by gatekeeper to determine which steps it should
#                       look for to close the tree.
#

CATEGORY_LINUX = '01Linux'
CATEGORY_LINUX64 = '02Linux64'
CATEGORY_WIN = '03Windows'
CATEGORY_MAC = '04Mac'
CATEGORY_ARM = '05Arm'
CATEGORY_ARM64 = '06Arm64'
CATEGORY_MIPS = '07Mips'
CATEGORY_PPC = '08PPC'
CATEGORY_GC_STRESS = '09GCStress'
CATEGORY_SANITIZERS = '10Sanitizers'
CATEGORY_MISC = '11Misc'
CATEGORY_FYI = '12FYI'

b_v8_linux_builder = {
  'name': 'V8 Linux - builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'slavebuilddir': 'linux-builder',
  # Build all revisions on linux 32 release.
  'mergeRequests': False,
  'auto_reboot' : False,
}

b_v8_linux_debug_builder = {
  'name': 'V8 Linux - debug builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'slavebuilddir': 'linux-builder',
  'auto_reboot' : False,
}

b_v8_linux_nosnap_builder = {
  'name': 'V8 Linux - nosnap builder',
  'factory':  m_annotator.BaseFactory('v8'),
  'slavebuilddir': 'linux-nosnap-builder',
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_nosnap_debug_builder = {
  'name': 'V8 Linux - nosnap debug builder',
  'factory':  m_annotator.BaseFactory('v8'),
  'slavebuilddir': 'linux-nosnap-builder',
  'category': CATEGORY_LINUX,
  'slavebuilddir': 'v8-linux-nosnap-debug',
  'auto_reboot' : False,
}

b_v8_linux_presubmit = {
  'name': 'V8 Linux - presubmit',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux = {
  'name': 'V8 Linux',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug_avx2 = {
  'name': 'V8 Linux - debug - avx2',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_vtunejit = {
  'name': 'V8 Linux - vtunejit',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI + '|vtunejit',
  'auto_reboot' : False,
}

b_v8_linux_x87_nosnap_debug_builder = {
  'name': 'V8 Linux - x87 - nosnap - debug builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI + '|x87',
  'auto_reboot' : False,
}

b_v8_linux_x87_nosnap_debug = {
  'name': 'V8 Linux - x87 - nosnap - debug',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI + '|x87',
  'auto_reboot' : False,
}

b_v8_linux_predictable = {
  'name': 'V8 Linux - predictable',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI + '|predictable',
  'auto_reboot' : False,
}

b_v8_linux_interpreted_regexp = {
  'name': 'V8 Linux - interpreted regexp',
  'builddir': 'v8-linux-interpreted-regexp',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI,
  'auto_reboot' : False,
}

b_v8_linux_noi18n_debug = {
  'name': 'V8 Linux - noi18n - debug',
  'builddir': 'v8-linux-noi18n-debug',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug = {
  'name': 'V8 Linux - debug',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_test262_debug = {
  'name': 'V8 Linux - test262 - debug',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_test262_es6_debug = {
  'name': 'V8 Linux - test262-es6 - debug',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_full_debug = {
  'name': 'V8 Linux - full debug',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI,
  'auto_reboot' : False,
}

b_v8_linux_shared = {
  'name': 'V8 Linux - shared',
  'slavebuilddir': 'linux-shared',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux64_builder = {
  'name': 'V8 Linux64 - builder',
  'slavebuilddir': 'linux64-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  # Build all revisions on linux 64 release.
  'mergeRequests': False,
  'auto_reboot' : False,
}

b_v8_linux64_debug_builder = {
  'name': 'V8 Linux64 - debug builder',
  'slavebuilddir': 'linux64-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_custom_snapshot_debug_builder = {
  'name': 'V8 Linux64 - custom snapshot - debug builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64 = {
  'name': 'V8 Linux64',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_debug = {
  'name': 'V8 Linux64 - debug',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_avx2 = {
  'name': 'V8 Linux64 - avx2',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_debug_avx2 = {
  'name': 'V8 Linux64 - debug - avx2',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_custom_snapshot_debug = {
  'name': 'V8 Linux64 - custom snapshot - debug',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux64_custom_snapshot_gcstress = {
  'name': 'V8 Linux64 GC Stress - custom snapshot',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS,
  'auto_reboot' : False,
}

b_v8_linux64_debug_greedy_allocator = {
  'name': 'V8 Linux64 - debug - greedy allocator',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX64,
  'auto_reboot' : False,
}

b_v8_linux_nosnap = {
  'name': 'V8 Linux - nosnap',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_nosnap_debug_1 = {
  'name': 'V8 Linux - nosnap - debug - 1',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_nosnap_debug_2 = {
  'name': 'V8 Linux - nosnap - debug - 2',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_arm_sim = {
  'name': 'V8 Linux - arm - sim',
  'slavebuilddir': 'arm-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot' : False,
}

b_v8_linux_arm_sim_debug = {
  'name': 'V8 Linux - arm - sim - debug',
  'slavebuilddir': 'arm-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot' : False,
}

b_v8_linux_arm_sim_novfp3 = {
  'name': 'V8 Linux - arm - sim - novfp3',
  'slavebuilddir': 'arm-sim-novfp3',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot' : False,
}

b_v8_linux_arm_sim_debug_novfp3 = {
  'name': 'V8 Linux - arm - sim - debug - novfp3',
  'slavebuilddir': 'arm-sim-novfp3',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot' : False,
}

b_v8_linux_mipsel_sim_builder = {
  'name': 'V8 Linux - mipsel - sim - builder',
  'slavebuilddir': 'mipsel-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

b_v8_linux_mips64el_sim_builder = {
  'name': 'V8 Linux - mips64el - sim - builder',
  'slavebuilddir': 'mips64el-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

b_v8_linux_mipsel_sim = {
  'name': 'V8 Linux - mipsel - sim',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

b_v8_linux_ppc_sim = {
  'name': 'V8 Linux - ppc - sim',
  'slavebuilddir': 'ppc-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_PPC,
  'auto_reboot' : False,
}

b_v8_linux_ppc64_sim = {
  'name': 'V8 Linux - ppc64 - sim',
  'slavebuilddir': 'ppc64-sim',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_PPC,
  'auto_reboot' : False,
}

b_v8_win32_builder = {
  'name': 'V8 Win32 - builder',
  'slavebuilddir': 'win-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_1 = {
  'name': 'V8 Win32 - 1',
  'slavebuilddir': 'win',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_2 = {
  'name': 'V8 Win32 - 2',
  'slavebuilddir': 'win',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_nosnap_shared = {
  'name': 'V8 Win32 - nosnap - shared',
  'builddir': 'v8-win32-nosnap-shared',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

# Non standard builddir because of path length limit (Test262 tests)
# for all win32 debug slaves.

b_v8_win32_debug_builder = {
  'name': 'V8 Win32 - debug builder',
  'slavebuilddir': 'win-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_debug_1 = {
  'name': 'V8 Win32 - debug - 1',
  'slavebuilddir': 'win',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_debug_2 = {
  'name': 'V8 Win32 - debug - 2',
  'slavebuilddir': 'win',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win32_debug_3 = {
  'name': 'V8 Win32 - debug - 3',
  'slavebuilddir': 'win',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_mac = {
  'name': 'V8 Mac',
  'slavebuilddir': 'mac',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MAC,
  'auto_reboot' : False,
}

b_v8_mac_debug = {
  'name': 'V8 Mac - debug',
  'slavebuilddir': 'mac',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MAC,
  'auto_reboot' : False,
}

b_v8_mac64 = {
  'name': 'V8 Mac64',
  'slavebuilddir': 'mac64',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MAC,
  'auto_reboot' : False,
}

b_v8_mac64_debug = {
  'name': 'V8 Mac64 - debug',
  'slavebuilddir': 'mac64',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MAC,
  'auto_reboot' : False,
}

b_v8_mac64_xcode = {
  'name': 'V8 Mac64 - xcode',
  'slavebuilddir': 'mac64_xcode',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MAC,
  'auto_reboot' : False,
}

b_v8_win64 = {
  'name': 'V8 Win64',
  'slavebuilddir': 'win64',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_win64_debug = {
  'name': 'V8 Win64 - debug',
  'slavebuilddir': 'win64',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_WIN,
  'auto_reboot' : False,
}

b_v8_linux_isolates = {
  'name': 'V8 Linux - isolates',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug_isolates = {
  'name': 'V8 Linux - debug - isolates',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_nosse3 = {
  'name': 'V8 Linux - nosse3',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug_nosse3 = {
  'name': 'V8 Linux - debug - nosse3',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_nosse4 = {
  'name': 'V8 Linux - nosse4',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug_nosse4 = {
  'name': 'V8 Linux - debug - nosse4',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_deadcode = {
  'name': 'V8 Linux - deadcode',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_code_serializer = {
  'name': 'V8 Linux - debug - code serializer',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_debug_greedy_allocator = {
  'name': 'V8 Linux - debug - greedy allocator',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX,
  'auto_reboot' : False,
}

b_v8_linux_gcmole = {
  'name': 'V8 Linux - gcmole',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_LINUX + '|mem_sheriff',
  'auto_reboot' : False,
}

b_v8_fuzz = {
  'name': 'V8 Fuzzer',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MISC,
  'auto_reboot' : False,
}

b_v8_linux_deopt_fuzzer = {
  'name': 'V8 Deopt Fuzzer',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MISC,
  'auto_reboot' : False,
}

b_v8_linux_random_deopt_fuzzer_debug = {
  'name': 'V8 Random Deopt Fuzzer - debug',
  'builddir': 'v8-linux-random-deopt-fuzzer-debug',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_FYI,
  'auto_reboot' : False,
}

b_v8_gcstress_1 = {
  'name': 'V8 GC Stress - 1',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS + '|mem_sheriff',
  'auto_reboot' : False,
}

b_v8_gcstress_2 = {
  'name': 'V8 GC Stress - 2',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS + '|mem_sheriff',
  'auto_reboot' : False,
}

b_v8_gcstress_3 = {
  'name': 'V8 GC Stress - 3',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS + '|mem_sheriff',
  'auto_reboot' : False,
}

b_v8_mac_gcstress = {
  'name': 'V8 Mac GC Stress',
  'slavebuilddir': 'mac',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS + '|mem_sheriff',
  'auto_reboot' : False,
}

b_v8_arm_gcstress = {
  'name': 'V8 Arm GC Stress',
  'slavebuilddir': 'arm',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_GC_STRESS + '|mem_sheriff',
  'auto_reboot': True,
}
builder_priorities['V8 Arm GC Stress'] = 2

b_v8_linux_gcc_4_8 = {
  'name': 'V8 Linux gcc 4.8',
  'builddir': 'v8-linux-gcc',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MISC,
  'auto_reboot' : False,
}

b_v8_linux64_asan = {
  'name': 'V8 Linux64 ASAN',
  'builddir': 'v8-linux64-asan',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_linux64_asan_debug_builder = {
  'name': 'V8 Linux64 ASAN - debug builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_linux64_tsan = {
  'name': 'V8 Linux64 TSAN',
  'builddir': 'v8-linux64-tsan',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_linux_arm64_sim_msan = {
  'name': 'V8 Linux - arm64 - sim - MSAN',
  'builddir': 'v8-linux-arm64-sim-msan',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_linux_memcheck = {
  'name': 'V8 Linux - memcheck',
  'slavebuilddir': 'linux',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_mac64_asan = {
  'name': 'V8 Mac64 ASAN',
  'slavebuilddir': 'mac64-asan',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_SANITIZERS,
  'auto_reboot' : False,
}

b_v8_arm_builder = {
  'name': 'V8 Arm - builder',
  'slavebuilddir': 'arm-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  # Build all revisions on arm 32 release.
  'mergeRequests': False,
  'auto_reboot' : False,
}

b_v8_arm_debug_builder = {
  'name': 'V8 Arm - debug builder',
  'slavebuilddir': 'arm-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot' : False,
}

b_v8_android_arm_builder = {
  'name': 'V8 Android Arm - builder',
  'slavebuilddir': 'android-arm-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'mergeRequests': False,
  'auto_reboot' : False,
}

b_v8_android_arm64_builder = {
  'name': 'V8 Android Arm64 - builder',
  'slavebuilddir': 'android-arm64-builder',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM64,
  'mergeRequests': False,
  'auto_reboot' : False,
}

b_v8_arm = {
  'name': 'V8 Arm',
  'slavebuilddir': 'arm',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot': True,
}
builder_priorities['V8 Arm'] = 1

b_v8_arm_debug_1 = {
  'name': 'V8 Arm - debug - 1',
  'slavebuilddir': 'arm',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot': True,
}
builder_priorities['V8 Arm - debug - 1'] = 1

b_v8_arm_debug_2 = {
  'name': 'V8 Arm - debug - 2',
  'slavebuilddir': 'arm',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_ARM,
  'auto_reboot': True,
}
builder_priorities['V8 Arm - debug - 2'] = 1

b_v8_mips_builder = {
  'name': 'V8 Mips - builder',
  'slavebuilddir': 'mips_nosnap',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

b_v8_mips_be_1 = {
  'name': 'V8 Mips - big endian - nosnap - 1',
  'slavebuilddir': 'mips_nosnap',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

b_v8_mips_be_2 = {
  'name': 'V8 Mips - big endian - nosnap - 2',
  'slavebuilddir': 'mips_nosnap',
  'factory': m_annotator.BaseFactory('v8'),
  'category': CATEGORY_MIPS,
  'auto_reboot' : False,
}

def CreateA64ReleaseBuilder():
  return {
    'name': 'V8 Linux - arm64 - sim',
    'slavebuilddir': 'arm64-sim',
    'factory': m_annotator.BaseFactory('v8'),
    'category': CATEGORY_ARM64,
    'auto_reboot' : False,
  }

def CreateA64DebugBuilder():
  return {
    'name': 'V8 Linux - arm64 - sim - debug',
    'slavebuilddir': 'arm64-sim',
    'factory': m_annotator.BaseFactory('v8'),
    'category': CATEGORY_ARM64,
    'auto_reboot' : False,
  }

def CreateA64NoSnapDebugBuilder(shard_count, shard_run):
  return {
    'name': 'V8 Linux - arm64 - sim - nosnap - debug - %d' % shard_run,
    'slavebuilddir': 'arm64-sim-nosnap',
    'factory': m_annotator.BaseFactory('v8'),
    'category': CATEGORY_ARM64,
    'auto_reboot' : False,
  }

def CreateA64GCStressBuilder():
  return {
    'name': 'V8 Linux - arm64 - sim - gc stress',
    'slavebuilddir': 'arm64-sim',
    'factory': m_annotator.BaseFactory('v8'),
    'category': CATEGORY_GC_STRESS + '|mem_sheriff',
    'auto_reboot' : False,
  }

b_v8_linux_arm64_sim = CreateA64ReleaseBuilder()
b_v8_linux_arm64_sim_debug = CreateA64DebugBuilder()

b_v8_linux_arm64_sim_nosnap_debug_1 = CreateA64NoSnapDebugBuilder(2, 1)
b_v8_linux_arm64_sim_nosnap_debug_2 = CreateA64NoSnapDebugBuilder(2, 2)

b_v8_linux_arm64_sim_gc = CreateA64GCStressBuilder()

c['builders'] = [b_v8_linux_builder,
                 b_v8_linux_debug_builder,
                 b_v8_linux_nosnap_builder,
                 b_v8_linux_nosnap_debug_builder,
                 b_v8_linux_presubmit,
                 b_v8_linux,
                 b_v8_linux_debug,
                 b_v8_linux_test262_debug,
                 b_v8_linux_test262_es6_debug,
                 b_v8_linux_shared,
                 b_v8_linux_nosnap,
                 b_v8_linux_nosnap_debug_1,
                 b_v8_linux_nosnap_debug_2,
                 b_v8_linux_isolates,
                 b_v8_linux_nosse3,
                 b_v8_linux_nosse4,
                 b_v8_linux_deadcode,
                 b_v8_linux_debug_isolates,
                 b_v8_linux_debug_nosse3,
                 b_v8_linux_debug_nosse4,
                 b_v8_linux_gcmole,
                 b_v8_linux_noi18n_debug,
                 b_v8_linux_code_serializer,
                 b_v8_linux_debug_avx2,
                 b_v8_linux_debug_greedy_allocator,
                 b_v8_linux64_builder,
                 b_v8_linux64_debug_builder,
                 b_v8_linux64_custom_snapshot_debug_builder,
                 b_v8_linux64,
                 b_v8_linux64_avx2,
                 b_v8_linux64_debug,
                 b_v8_linux64_custom_snapshot_debug,
                 b_v8_linux64_debug_avx2,
                 b_v8_linux64_debug_greedy_allocator,
                 b_v8_win32_builder,
                 b_v8_win32_debug_builder,
                 b_v8_win32_1,
                 b_v8_win32_2,
                 b_v8_win32_nosnap_shared,
                 b_v8_win32_debug_1,
                 b_v8_win32_debug_2,
                 b_v8_win32_debug_3,
                 b_v8_win64,
                 b_v8_win64_debug,
                 b_v8_mac,
                 b_v8_mac_debug,
                 b_v8_mac64,
                 b_v8_mac64_debug,
                 b_v8_mac64_xcode,
                 b_v8_arm_builder,
                 b_v8_arm_debug_builder,
                 b_v8_android_arm_builder,
                 b_v8_arm,
                 b_v8_arm_debug_1,
                 b_v8_arm_debug_2,
                 b_v8_linux_arm_sim,
                 b_v8_linux_arm_sim_debug,
                 b_v8_linux_arm_sim_novfp3,
                 b_v8_linux_arm_sim_debug_novfp3,
                 b_v8_android_arm64_builder,
                 b_v8_linux_arm64_sim,
                 b_v8_linux_arm64_sim_debug,
                 b_v8_linux_arm64_sim_nosnap_debug_1,
                 b_v8_linux_arm64_sim_nosnap_debug_2,
                 b_v8_mips_builder,
                 b_v8_mips_be_1,
                 b_v8_mips_be_2,
                 b_v8_linux_mipsel_sim_builder,
                 b_v8_linux_mips64el_sim_builder,
                 b_v8_linux_mipsel_sim,
                 b_v8_linux_ppc_sim,
                 b_v8_linux_ppc64_sim,
                 b_v8_gcstress_1,
                 b_v8_gcstress_2,
                 b_v8_gcstress_3,
                 b_v8_linux64_custom_snapshot_gcstress,
                 b_v8_mac_gcstress,
                 b_v8_arm_gcstress,
                 b_v8_linux_arm64_sim_gc,
                 b_v8_linux64_asan,
                 b_v8_linux64_asan_debug_builder,
                 b_v8_linux64_tsan,
                 b_v8_linux_arm64_sim_msan,
                 b_v8_linux_memcheck,
                 b_v8_mac64_asan,
                 b_v8_fuzz,
                 b_v8_linux_deopt_fuzzer,
                 b_v8_linux_gcc_4_8,
                 b_v8_linux_vtunejit,
                 b_v8_linux_x87_nosnap_debug_builder,
                 b_v8_linux_x87_nosnap_debug,
                 b_v8_linux_predictable,
                 b_v8_linux_full_debug,
                 b_v8_linux_interpreted_regexp,
                 b_v8_linux_random_deopt_fuzzer_debug]

# Associate the slaves to the builders. The configuration is in slaves.cfg.
slaves = slaves_list.SlavesList('slaves.cfg', 'V8')
for builder in c['builders']:
  builder['slavenames'] = slaves.GetSlavesName(builder=builder['name'])


####### BUILDSLAVES

# The 'slaves' list defines the set of allowable buildslaves. List all the
# slaves registered to a builder. Remove dupes.
c['slaves'] = master_utils.AutoSetupSlaves(c['builders'],
                                           config.Master.GetBotPassword())

# Make sure everything works together.
# TODO(phajdan.jr): Make slave pools sane, http://crbug.com/435559 .
master_utils.VerifySetup(c, slaves, enforce_sane_slave_pools=False)


####### STATUS TARGETS

# TODO(machenbach): I think the next line is not used and has no effect:
# Adds common status and tools to this master.
# Buildbot master url:
# Must come before AutoSetupMaster().
c['buildbotURL'] = ActiveMaster.buildbot_url
master_utils.AutoSetupMaster(c, ActiveMaster,
    public_html='../master.chromium/public_html',
    tagComparator=comparator,
    templates=['./templates', '../master.chromium/templates'])

if MAIL_NOTIFIER:
  import mail_notifier_cfg
  mail_notifier_cfg.Update(config, ActiveMaster, c)

# Do it at the end to override values set by AutoSetupMaster, the default is
# too low. Must keep at least a few days worth of builds.
c['buildHorizon'] = 3000
c['logHorizon'] = 3000
# Must be at least 2x the number of slaves.
c['eventHorizon'] = 200

####### PROJECT IDENTITY

c['projectName'] = ActiveMaster.project_name
c['projectURL'] = config.Master.project_url
